package com.ithengxing.d2_udp1;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

/*
 * 一发一收
 */

public class ClientUdp {
    public static void main(String[] args) throws Exception {
        System.out.println("============客户端启动============");
        //创建发送端对象：发送端自带默认的端口号（人）
        DatagramSocket sc = new DatagramSocket(6666);

        //创建一个数据包对象封装数据
        byte[] bytes = "听到我说话了吗,回信息了".getBytes();
        DatagramPacket packet = new DatagramPacket(bytes, bytes.length, InetAddress.getLocalHost(), 8888);

        //发送数据
        sc.send(packet);

        sc.close();
    }
}
